package com.ildepinc.persistence.concretes.models;

import com.ildepinc.persistence.abstracts.SequenceGeneric;
// You should customize this class
// depending on the database engine
// you want to use.
// This version is for Apache Derby
public class LanguageSequence extends SequenceGeneric {

  public LanguageSequence() {
    this.clear();
  }

  public LanguageSequence(
      String schema,
      String sequenceName,
      String sqlCreate,
      String sqlDrop,
      String sqlNextVal,
      String sqlCurrVal) {
    this.clear();
    this.setDefaults(schema);
    this.setSequenceName(sequenceName);
    this.setSqlCreate(sqlCreate);
    this.setSqlDrop(sqlDrop);
    this.setSqlNextVal(sqlNextVal);
    this.setSqlCurrVal(sqlCurrVal);
  }

  public LanguageSequence(String schema) {
    this.clear();
    this.setDefaults(schema);
  }

  @Override
  public void setDefaults(String schema) {
    super.setDefaults(schema);
    this.setSequenceName("SEQ_LANGUAGES");
    String fullQualifiedName = this.getSchema() + "." + this.getSequenceName();
    this.setSqlCreate("CREATE SEQUENCE "
        + fullQualifiedName
        + " AS BIGINT"
        + " START WITH 1"
        + " INCREMENT BY 1"
        + " MINVALUE 1"
    );
    this.setSqlDrop("DROP SEQUENCE "
      + fullQualifiedName
      + " RESTRICT"
    );
    this.setSqlNextVal("VALUES (NEXT VALUE FOR "
      + fullQualifiedName
      + ")"
    );
    this.setSqlCurrVal(null);
  }

}
